<?php
	
	require_once(dirname(__FILE__)."/../core/safeParam.php");
	
	if(isset($_GET['action'])){
		$action = $_GET['action'];	
	}
	
	switch ($action) {
		default:
		if (!isset($_GET['lid'])) {
			
			if($_SESSION['admin'] == 1){
				$results = $database->select("SELECT * FROM users ORDER by id ");
			}
			
      	
      	echo '
			<div class="tituloOpcionesAdmin">
				<img src="images/icons/user_edit.png"/>
				Usuarios
			</div>
							
      	<table cellspacing="2" cellpadding="2" border="0" class="table">
      		<tr>
      			<th>ID</th>
      			<th>Nombre</th>
      			<th>E-mail</th>
      			<th>Acciones</th>
      		</tr>';
          
          if ($results != false) {
          	for ($i = 0; $i < count($results); $i++) {
          		echo '
          		<tr>
						<td>' . $results[$i]['id'] . '  </td>
          			
          			<td>
          				<a href="index.php?edit=users&lid=' . $results[$i]['id'] . '">' . $results[$i]['last_name'] . ',' . $results[$i]['name'] . '  </a>
          			</td>
          			
          			<td>
          				<a href="mailto:' . $results[$i]['email'] . '">' . $results[$i]['email'] . '</a>
          			</td>
          			
          			<td>
          				<a href="index.php?edit=users&action=edit&lid=' . $results[$i]['id'] . '"><img src="application_edit.png"  border="0">Editar</a> 
          				<a href="../functions/users.php?function=delete&id=' . $results[$i]['id'] . '"><img src="delete.png"  border="0">Borrar</a> 
         			</td>
        			</tr>';
				} 
      	 }
      	
      	echo '</table>';
		} else {
			$results = $database->select("SELECT * FROM users WHERE    id = " . $_GET['lid'] . " ");
			
			echo '
			<div style="margin:20px;">
				<h2>Información del Usuario: ' .$results[0]["id"]. '</h2>				
			</div>
			
			<form action="../functions/users.php?function=edit" method="post">
				<input type="hidden" name="id" value="' . $results[0]['id'] . '">
					<table cellspacing="0" cellpadding="5"   style="width:65%; border:2px solid #CCC; margin:auto;">
                 <tr style="border:1px dashed #CCC;">
              	     <td>Nombre:</td>
                    <td><input type="text" name="name" value="' . $results[0]['name'] . '"></td>
            	  </tr>
            	  
            	  <tr style="border:1px dashed #CCC;">
              	     <td>Apellido:</td>
                    <td><input type="text" name="last_name" value="' . $results[0]['last_name'] . '"></td>
                 </tr>
            	  
            	  <tr style="border:1px dashed #CCC;">
                    <td>E-mail:</td>
                    <td><input type="text" name="address" value="' . $results[0]['email'] . '"></td>
                 </tr>
                 
                 <tr style="border:1px dashed #CCC;">
                    <td>Dirección:</td>
                    <td><input type="text" name="address" value="' . $results[0]['address'] . '"></td>
                 </tr>
                 
                 <tr style="border:1px dashed #CCC;">
                    <td>Dirección 2:</td>
                    <td><input type="text" name="address2" value="' . $results[0]['address2'] . '"></td>
                 </tr>
                 
                 <trstyle="border:1px dashed #CCC;">
                    <td>Ciudad:</td>
                    <td><input type="text" name="city" value="' . $results[0]['city'] . '"></td>
                 </tr>
                                  
                 <tr style="border:1px dashed #CCC;">
                    <td>Teléfono:</td>
                    <td><input type="text" name="phone" value="' . $results[0]['phone'] . '"></td>
                 </tr>
                 
                 <tr style="border:1px dashed #CCC;">
                    <td>
                		   <font color="red" size="2em">Cambiar contraseña (opcional):</font>
                		   <br /><br />
                		   Contraseña nueva:
                    </td>
                       
                    <td>
                       <br /><br />
                       <input type="password" name="password" value="">
                    </td>
             	  </tr>
            
            	  <tr style="border:1px dashed #CCC;">
                    <td>Confirmar contraseña:</td>
                    <td><input type="password" name="password_confirm" value=""></td>
                 </tr>
                                  
                 <tr style="border:1px dashed #CCC;">
                    <td colspan="2">
                       <div align="center">
                          <input type="submit" value="Guardar" style="padding:10px";>
                       </div>
                    </td> 
                 </tr>
              </table>
           </form>
           ';
		}//else
		break;
		
		case "add":
		echo '
		<form action="../functions/locations.php?function=add" method="post">
			<input type="hidden" name="id" value="' . $results[0]['id'] . '">
			<table cellspacing="0" cellpadding="2" border="0" class="table_form" style="text-align:left">
				<tr>
          		<td>Location Name:</td>
          		<td><input type="text" name="name" value"' . $results[0]['name'] . '"></td>
        		</tr>
        		
        		<tr>
          		<td>Address:</td>
          		<td><input type="text" name="address" value"' . $results[0]['address'] . '"></td>
        		</tr>
        		
        		<tr style="background-color:CCC">
          		<td>City:</td>
          		<td><input type="text" name="city" value"' . $results[0]['city'] . '"></td>
        		</tr>
        		
        		<tr>
          		<td>State (Abbr):</td>
          		<td><input type="text" name="state" value"' . $results[0]['state'] . '"></td>
        		</tr>
        		
        		<tr style="background-color:CCC">
          		<td>Teléfono:</td>
          		<td><input type="text" name="phone" value"' . $results[0]['phone'] . '"></td>
        		</tr>
        		
        		<tr>
          		<td>Fax:</td>
          		<td><input type="text" name="fax" value"' . $results[0]['fax'] . '"></td>
        		</tr>
        
        		<tr>
          		<td>E-mail:</td>
          		<td><input type="text" name="email" value"' . $results[0]['email'] . '"></td>
        		</tr>

        		<tr>
          		<td colspan="2" align="center>
          			<input type="submit" value="Save">
          		</td>
        		</tr>
      	</table>
    	</form>
    	';
    	break;
}
?>
